﻿using SuperSocket;
using SuperSocket.Server;
using SuperSocket.WebSocket.Server;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace superSocketApi.TestAppSession
{
    public class TestSession : WebSocketSession
    {
        public string Name { get; set; }

		protected override async ValueTask OnSessionConnectedAsync()
		{
			// do something right after the sesssion is connected

			this["DeviceId"] = 0;
			this["TcpSocket"] = null;
			if (GlobalSystem.theHost.AsServer().GetSessionContainer().GetSessions() != null)
			{
				IAppSession s = GlobalSystem.theHost.AsServer().GetSessionContainer().GetSessionByID(this.Path.Substring(1));
				if (s != null && s.State == SessionState.Connected)
				{
					s["WebSocket"] = this;
					//this["DeviceId"] = s["WebSocket"];
					this["TcpSocket"] = s;
				}
				else
				{
					await this.CloseAsync();
				}
			}
			else
			{
				await this.CloseAsync();
			}

			await Task.Delay(0);
		}
	}
}
